home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15125 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Turbo 3.0 compiler bug -- I MEAN IT!!!!
  5. Date: 3 Apr 1996 17:09:37 GMT
  6. Organization: Borland International
  7. Message-ID: <4jubch$52c@druid.borland.com>
  8. References: <4jpp78$85b@news.vanderbilt.edu> <4jr8m7$kpm@News.Dal.Ca>
  9. NNTP-Posting-Host: pbecker.borland.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <4jr8m7$kpm@News.Dal.Ca>, Klaus.Eichele@Dal.Ca says...
  15. >
  16. >haseltbt@ctrvax.vanderbilt.edu (Bennett Haselton) wrote:
  17. >>       Hello world,
  18. >
  19. >>               i've found what appears to be a bug in the Turbo 3.0 C++ 
  20. >>compiler.  Apparently if you write a while loop that is immediately preceded 
  21. by
  22. >>code identical to that contained in the while loop--and the "while" statement 
  23. >>is true at the time the code immediately preceding it is analyzed--then the 
  24. >>compiler ignores this extra code preceding the while loop as unnecessary.  
  25. >>Seems reasonable--equivalent output, right?
  26. >>       The problem is in the debugging process.  i had written code with the 
  27. >>above-mentioned redundancy to make it easier to read, and in the debugging 
  28. >>cycle i tried setting breakpoints within the block of "redundant" code.  
  29. Turbo 
  30. >>C++ will not allow breakpoints to be set at empty or commented space; 
  31. >>unfortunately the redundant code was compiled as "empty space" and 
  32. breakpoints 
  33. >>were forbidden there.  Worse, when the compiler skipped to a breakpoint 
  34. inside 
  35. >>the while loop, it became obvious from the values of watch variables that the 
  36. >>redundant code had been skipped entirely.
  37. >   <SNIP>
  38. >
  39. >Hi, I don't think your discovery qualifies as a bug. For your
  40. >particular problem, however, you might want to try to switch of
  41. >optimization. Without optimization, you should get the result you
  42. >expect.
  43.  
  44. To clarify a bit:
  45.  
  46. InitialCode();
  47. while( Condition() )
  48.     {
  49.     SomeCode();
  50.     InitialCode();
  51.     }
  52.  
  53. The compiler does tail merging here, and generates code as if you had written 
  54. your code like this:
  55.  
  56. goto Inner;
  57. while( Condition() )
  58.     {
  59.     SomeCode();
  60. Inner:
  61.     InitialCode();
  62.     }
  63.  
  64. Both code sequences do the same thing. When you try to debug, though, it can be 
  65. confusing, because the generated code doesn't directly correspond to the source 
  66. code.
  67.  
  68.